import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_util/common/extentions.dart';

class MyDialog extends Dialog {
  final String title;
  final String detail;
  final String confirmText;
  final String cancelText;
  final void Function() onConfirm;
  final void Function()? onCancel;

  const MyDialog({Key? key, required this.title, required this.detail, required this.onConfirm, this.onCancel, this.confirmText='Confirm', this.cancelText='Cancel'})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency, // 透明度
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              margin: EdgeInsets.only(left: 33.w, right: 33.w),
              decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.w), color: Colors.white),
              child: Column(
                children: [
                  SizedBox(height: 20.w),
                  Text(title,
                      style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w500, color: "#333333".toColor())),
                  SizedBox(height: 10.w),
                  Padding(
                    padding: EdgeInsets.only(left: 20.w, right: 20.w),
                    child: Text(detail,
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: "#868391".toColor())),
                  ),
                  SizedBox(height: 20.w),
                  Container(
                    height: 1.w,
                    color: '#E0E0E0'.toColor(),
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: GestureDetector(
                          behavior: HitTestBehavior.translucent,
                          child: Container(
                              height: 49.w,
                              child: Text(cancelText,
                                  style: TextStyle(
                                      fontSize: 14.sp, fontWeight: FontWeight.w500, color: "#868391".toColor())),
                              alignment: Alignment.center),
                          onTap: () {
                            if (onCancel != null) {
                              onCancel!();
                            } else {
                              Navigator.of(context).pop();
                            }
                          },
                        ),
                      ),
                      Container(
                        width: 1.w,
                        height: 20.w,
                        color: '#E0E0E0'.toColor(),
                      ),
                      Expanded(
                          child: GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        child: Container(
                            height: 49.w,
                            color: Colors.transparent,
                            child: Text(confirmText,
                                style: TextStyle(
                                    fontSize: 14.sp, fontWeight: FontWeight.w500, color: "#8667FE".toColor())),
                            alignment: Alignment.center),
                        onTap: () {
                          onConfirm();
                        },
                      ))
                    ],
                  )
                ],
              )),
        ],
      ),
    );
  }
}
